package com.rk.admin.config;
import com.rk.admin.tools.SysConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfigurer implements WebMvcConfigurer {


    @Value("${environment.system}")
    private String system;

//    linux系统下
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        if("linux".equals(system)){

            //放行上传的图片
            //  将路由/articImg/** 映射到真实路径
            registry.addResourceHandler("/articImg/**").addResourceLocations("file:/www/wwwroot/ylu/image/articImg/");
            //  将路由/teacherImg/** 映射到真实路径
            registry.addResourceHandler("/teacherImg/**").addResourceLocations("file:/www/wwwroot/ylu/image/teacherImg/");
            //  将路由/lunImg/** 映射到真实路径
            registry.addResourceHandler("/lunImg/**").addResourceLocations("file:/www/wwwroot/ylu/image/lunImg/");


        }else if("windows".equals(system)){
            //获取项目在本机上的路径   动态获取
            String ValuePath = System.getProperty("user.dir");
            //教师头像存储的真实路径
            String tecacherPath=ValuePath+ SysConstant.TEACHERHEAD_WINDOWS;
            //文章图片存储的真实路径
            String articPath=ValuePath+SysConstant.ARTICLEiMG_WINDOWS;
            //轮播图图片存储的真实路径
            String lunPath=ValuePath+SysConstant.HOMEIMG_WINDOWS;

            //放行上传到后端的图片
            //将路由/teacherImg/** 映射到真实路径
            registry.addResourceHandler("/teacherImg/**").addResourceLocations("file:"+tecacherPath);
            //将路由/articImg/** 映射到真实路径
            registry.addResourceHandler("/articImg/**").addResourceLocations("file:"+articPath);
            //将路由/lunImg/** 映射到真实路径
            registry.addResourceHandler("/lunImg/**").addResourceLocations("file:"+lunPath);
        }


        //放行 前端打包的静态资源
        //放行index.html
        registry.addResourceHandler("/static/**").
                addResourceLocations("classpath:/static/");
        //放行js
        registry.addResourceHandler("/js/**").
                addResourceLocations("classpath:/static/static/js/");
        //放行css
        registry.addResourceHandler("/css/**").
                addResourceLocations("classpath:/static/static/css/");
        //放行fonts
        registry.addResourceHandler("/fonts/**").
                addResourceLocations("classpath:/static/static/fonts/");
        //放行img
        registry.addResourceHandler("/img/**").
                addResourceLocations("classpath:/static/static/img/");

        WebMvcConfigurer.super.addResourceHandlers(registry);
    }


    //windows下
//
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //获取项目在本机上的路径   动态获取
//        String ValuePath = System.getProperty("user.dir");
//        //教师头像存储的真实路径
//        String tecacherPath=ValuePath+ SysConstant.TEACHERHEAD;
//        //文章图片存储的真实路径
//        String articPath=ValuePath+SysConstant.ARTICLEiMG;
//        //轮播图图片存储的真实路径
//        String lunPath=ValuePath+SysConstant.HOMEIMG;
//
//        //放行上传到后端的图片
//        //将路由/teacherImg/** 映射到真实路径
//        registry.addResourceHandler("/teacherImg/**").addResourceLocations("file:"+tecacherPath);
//        //将路由/articImg/** 映射到真实路径
//         registry.addResourceHandler("/articImg/**").addResourceLocations("file:"+articPath);
//        //将路由/lunImg/** 映射到真实路径
//        registry.addResourceHandler("/lunImg/**").addResourceLocations("file:"+lunPath);
//
//        //放行 前端打包的静态资源
//        //放行index.html
//        registry.addResourceHandler("/static/**").
//                addResourceLocations("classpath:/static/");
//        //放行js
//        registry.addResourceHandler("/js/**").
//                addResourceLocations("classpath:/static/static/js/");
//        //放行css
//        registry.addResourceHandler("/css/**").
//                addResourceLocations("classpath:/static/static/css/");
//        //放行fonts
//        registry.addResourceHandler("/fonts/**").
//                addResourceLocations("classpath:/static/static/fonts/");
//        //放行img
//        registry.addResourceHandler("/img/**").
//                addResourceLocations("classpath:/static/static/img/");
//        WebMvcConfigurer.super.addResourceHandlers(registry);
//    }
//

}
